package jmine.tec.web.wicket.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import org.apache.wicket.util.convert.IConverter;

import bancosys.tec.utils.date.Date;
import bancosys.tec.utils.date.DateUtils;

/**
 * Converter de date do tec.
 * 
 * @author wagner
 */
public class TecDateConverter implements IConverter {

    /**
     * {@inheritDoc}
     */
    public Object convertToObject(String value, Locale locale) {
        if (value == null) {
            return value;
        }
        final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        try {
            return new Date(sdf.parse(value));
        } catch (final ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }

    /**
     * {@inheritDoc}
     */
    public String convertToString(Object date, Locale locale) {
        return DateUtils.dateToStringDDMMYYYY((Date) date);
    }

}
